package com.huayi.datagovernance.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.huayi.datagovernance.common.SysConstant;
import com.huayi.datagovernance.entity.TZyRcvInfo;
import com.huayi.datagovernance.dao.slave.TZyRcvInfoMapper;
import com.huayi.datagovernance.exception.BizException;
import com.huayi.datagovernance.service.TZyRcvInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huayi.datagovernance.vo.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dalong
 * @since 2021-05-06
 */
@Service
@Slf4j
public class TZyRcvInfoServiceImpl extends ServiceImpl<TZyRcvInfoMapper, TZyRcvInfo> implements TZyRcvInfoService {

    @Override
    public boolean saveJlxCollectInfoBatch(List<TZyRcvInfo> rcvInfos) {
        try {
            if (CollUtil.isEmpty(rcvInfos)){
                return false;
            }
            for (TZyRcvInfo rcvInfo : rcvInfos) {
                if (StrUtil.isBlank(rcvInfo.getAppNo())){
                    throw new BizException("营销工单号不能为空");
                }
                if (StrUtil.isBlank(rcvInfo.getBxtm())){
                    throw new BizException("表箱条码不能为空");
                }
                //填充公共字段（时间，状态）
                rcvInfo.setAuditStatus(SysConstant.TQ_BX_COLLECT_NO);
                rcvInfo.setReadTime(new Date());
                rcvInfo.setWriteTime(new Date());
                this.save(rcvInfo);
            }
//            return this.saveBatch(rcvInfos);
            /*    if (isSuccess){
                return ResponseResult.success(isSuccess, "保存成功");
            }else {
                return ResponseResult.failed(isSuccess, "保存失败");
            }*/
            return true;
        } catch (Exception e) {
            log.error("计量箱采集信息保存失败",e);
            return false;
        }
    }
}
